package com.example.uitls;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by leonardo on 17/5/27.
 */

public class DateUtils {

    /**
     * 获取时间戳（HH表示 为24小时制，hh 表示 12小时制）
     *
     * @return
     */
    public static String getTimeStamp() {
        Date date = new Date();
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
        return timestamp;
    }


    public static long TimeStrToTimeStamp(String str){
        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
        Date date= null;
        try {
            date = simpleDateFormat .parse(str);
            long timeStemp =date.getTime();
            return timeStemp;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }


    /**
     * 返回当前系统时间
     */
    public static String getDataTime(String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        return df.format(new Date());
    }

    /**
     * 获取当前系统时间 
     * @return
     */
    public static int[] getCurrentDate() {
        int[] dateBundle = new int[3];
        String[] temp = getDataTime("yyyy-MM-dd").split("-");

        for (int i = 0; i < 3; i++) {
            try {
                dateBundle[i] = Integer.parseInt(temp[i]);
            } catch (Exception e) {
                dateBundle[i] = 0;
            }
        }
        return dateBundle;
    }



}
